$(function(){
	getRecommandClass(0,6);//首页右侧精选话题数据加载
	getHomePageTopic(0,15);//主页话题预览查询
	getRecommandActivity(0,6);
	setCarsouelData();
});
//热门活动
function getRecommandActivity(pos_idx1,count1){
	$.ajax({
		type : 'POST',
		dataType:'json', 
		url : ctp + '/interface/hotActivity',
		data: {
			type:0,//0 推荐预览查询 1关注预览差查询	2热门预览查询 3最新预览查询
			pos_idx:pos_idx1,
			type:3,
			count:count1
		},
		success:function(data){
			if(data.code==200){
				//console.log(JSON.stringify(data.data));
				var result='';
				for(var i=0;i<data.data.length;i++){
                  result+='<div class="feed-element">';
				  result+='<a href="web/activityDetail.jsp?class_id='+data.data[i].class_id+'&topic_id='+data.data[i].topic_id+'" class="pull-left">';
				  result+='<img alt="image" class="img-circle" src="'+data.data[i].cover_pic+'">';
				  result+='</a>';
                  result+='<div class="media-body ">';
                  result+='<div><a href="web/activityDetail.jsp?class_id='+data.data[i].class_id+'&topic_id='+data.data[i].topic_id+'" ><strong>'+data.data[i].title+'</strong></a></div>';
                  result+='<div><small>已有'+data.data[i].join_cnt+'人参与</small></div>';
                  result+='</div>';
                  result+='</div>';
				}
				$('#recommendActivity').html(result);
			}
		},
		error:function(data){
		}
    });
}
//精选班组数据加载
function getRecommandClass(pos_idx1,count1){
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/classList',
			data: {
				type:4,//0 推荐预览查询 1关注预览差查询	2热门预览查询 3最新预览查询 4精选班组
				pos_idx:pos_idx1,
				count:count1
			},
			success:function(data){
				if(data.code==200){
					//console.log(JSON.stringify(data.data));
					var result='';
					for(var i=0;i<data.data.length;i++){
					  var indro=data.data[i].indroduce.length>40?(data.data[i].indroduce.substring(0,40)+"..."):data.data[i].indroduce
	                  result+='<div class="feed-element">';
					  result+='<a href="web/classDetail.jsp?class_id='+data.data[i].class_id+'" class="pull-left">';
					  result+='<img alt="image" class="img-circle" src="'+data.data[i].class_pic+'">';
					  result+='</a>';
	                  result+='<div class="media-body ">';
	                  result+='<div><a href="web/classDetail.jsp?class_id='+data.data[i].class_id+'" ><strong>'+data.data[i].class_name+'</strong></a></div>';
	                  result+='<div><small>'+indro+'</small></div>';
	                  result+='</div>';
	                  result+='</div>';

					}
					$('#recommendClass').html(result);
				}
			},
			error:function(data){
			}
	    });
}
//首页推荐话题数据加载
function getHomePageTopic(pos_idx1,count1){
	
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/homepagetopicSearch',
			data: {
				type:0,//0 推荐预览查询 1关注预览差查询	2热门预览查询 3最新预览查询
				pos_idx:pos_idx1,
				count:count1
			},
			success:function(data){
				if(data.code==200){
					var result='';
					for(var i=0;i<data.data.length;i++){
						var cover_pic='';
						//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
						if(data.data[i].cover_pic ==''){
							if(data.data[i].pic_list==''){
								cover_pic="images/nopic.jpg";
							}else{
								cover_pic=data.data[i].pic_list[0];
							}
							
						}else{
							cover_pic=data.data[i].cover_pic;
						}				
//						result+='<div class="ibox-content">';
//						result+='<div class="row">';
//						result+='<div class="col-md-3">';
//		                result+='</div>';
//		                result+='<div class="col-md-9" >';
//						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//						result+='<h2>';
//	                    if(data.data[i].is_top==1){
//	                    	result+='<button class="btn btn-danger" type="button">置顶</button>';
//	                    }
//	                    result+=data.data[i].title+'</h2>';
//	               		result+='</a>';
//	                    result+='<div class="small m-b-xs text-right ">';
//	                    result+='<span class="text-muted"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='<div class="row">';
//	                    result+='<div class="col-md-3" > <img  class="img-responsive"   src="'+cover_pic+'"></div>';
//	                    result+='<br>';
//	                    result+='<div class="col-md-9" ><p>'+data.data[i].indroduce+'</p> </div>';
//	                    result+='</div>';
//	                    result+='<div class="row m-t-sm ">';
//	                    result+='<div class="col-md-3">';
//	                    result+='</div>';
//	                    result+='<div class="col-md-9">';
//	                    result+='<div class="col-md-4 text-bottom">  ';
//	                    result+='<img  id="pic" class="img-circle" src="'+data.data[i].class_pic+'"  style="width: 35px;height:35px">&nbsp;<button class="btn btn-success"  type="button">'+data.data[i].class_name+'</button>';
//	                    result+='</div>';
//	                    result+='<div class="col-md-2 text-bottom"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
//	                    result+='<button id="is_forward_btn" style="margin-bottom:5px;"  class="btn btn-white " type="button">';
//	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-bottom "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
//	                    result+='<button id="is_forward_btn" style="margin-bottom:5px;" class="btn btn-white " type="button" > ';
//	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
//	                    result+='</button></a></div>';
//	                    result+='<div class="col-md-2 text-center " >'; 
//	                    if(data.data[i].is_thumbs==0){//用户已经点赞
//	                    	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white " type="button"  onclick="topicthumbsUp('+data.data[i].topic_id+',10)"><i class="fa fa-thumbs-o-up" style="color:red"   id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
//	                    }else{//用户还未点赞
//	                    	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white " type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"  id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i> ';
//	                    }
//	                    result+='</button></div>';
//	                    result+='</div>';
//	                    result+='</div>';
//	                    result+='</div>';
//					}
						
						result+='<div class="ibox-content">';
						result+='<div class="row">';
						result+='<div class="col-md-3"> <img  class="img-responsive" src="'+cover_pic+'"></div>';
				        result+='<div class="col-md-9">';
						result+='<div class="row">';
				        result+='<div class="col-md-12 ">';
				        result+='<div class="col-md-8"> ';
						result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
						result+='<h2>';		
				        if(data.data[i].is_top==1){
				        	result+='<button class="btn btn-danger" type="button">置顶</button>';        	        	
				        }
				        if (data.data[i].type==1){
				    		result+='&nbsp;<button class="btn btn-danger" type="button">投票</button>&nbsp;';
				    	}else if (data.data[i].type==2){
				    		result+='&nbsp;<button class="btn btn-danger" type="button">问卷调查</button>&nbsp;';
				    	}else if (data.data[i].type==3){
				    		result+='&nbsp;<button class="btn btn-danger" type="button">活动报名</button>&nbsp;';
				    	}
				        result+=data.data[i].title+'</h2>';
				   		result+='</a>';
				   	    result+='</div>';
				        result+='<div class=" col-md-4 ">';
				        result+='<span class="pull-right"><i class="fa fa-clock-o"></i>'+data.data[i].create_time+'</span> ';
				        result+='</div>';
				        result+='</div>';
				        result+='</div>';
				        result+='<br>';
				        result+='<div class="row">';
				        result+='<div class="col-md-12" ><div class="col-md-12" ><p>'+data.data[i].indroduce+'</p></div></div>';
				        result+='</div>';
				        result+='<div class="row m-t-sm " >';
				        result+='<div class="col-md-9">';
	                    result+='<div class="col-md-4 ">  ';
	                    result+='<img  id="pic" class="img-circle" src="'+data.data[i].class_pic+'"  style="width: 20px;height:20px">&nbsp;<button class="btn btn-success btn-xs"  type="button">'+data.data[i].class_name+'</button>';
	                    result+='</div>';
//				        result+='<div class="col-md-2 text-center">  ';
//				        result+='<button class="btn btn-success btn-xs " type="button">'+data.data[i].create_user_name+'</button>';
//				        result+='</div>';
//				        result+='<div class="col-md-2 text-bottom"><a javascript:void(0)  class="btn-link">';
//				        result+='<button id="is_forward_btn" class="btn btn-white btn-xs" type="button">';
//				        if (data.data[i].type==0){
//				    		 result+=''+data.data[i].read_cnt+'人已阅读';
//				    	}else {
//				    		 result+=''+data.data[i].join_cnt+'人参与';
//				    	}
//				        result+='</button></a></div>';
	                    result+='<div class="col-md-2 text-bottom"><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">';
	                    result+='<button id="is_forward_btn"   class="btn btn-white btn-xs" type="button">';
	                    result+='<i class="fa fa-external-link">'+data.data[i].forward_cnt+'转发 </i>';
	                    result+='</button></a></div>';
	                    result+='<div class="col-md-2 text-bottom "><a javascript:void(0) onclick="Common.openDetailPage('+data.data[i].topic_id+','+data.data[i].class_id+','+data.data[i].type+')" class="btn-link">'; 
	                    result+='<button id="is_forward_btn"  class="btn btn-white btn-xs" type="button" > ';
	                    result+='<i class="fa fa-commenting-o">'+data.data[i].comment_cnt+'评论</i>   ';
	                    result+='</button></a></div>';
	                    result+='<div class="col-md-2 text-center " >'; 
	                    if(data.data[i].is_thumbs==0){//用户已经点赞
	                    	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white btn-xs" type="button"  onclick="topicthumbsUp('+data.data[i].topic_id+',10)"><i class="fa fa-thumbs-o-up" style="color:red"   id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i>  '; 
	                    }else{//用户还未点赞
	                    	result+='<button id="zan_'+data.data[i].topic_id+'" class="btn btn-white btn-xs" type="button" onclick="topicthumbsUp('+data.data[i].topic_id+',2)" ><i class="fa fa-thumbs-o-up"  id="'+data.data[i].topic_id+'_a" >'+data.data[i].thumbs_cnt+'点赞 </i> ';
	                    }
	                    result+='</button></div>';
				        result+='</div>';
				        result+='</div>';
				        result+='</div>';
				        result+='</div>';
				        result+='</div>';
					}
					if(data.data.length>=15){
						result+='<button class="btn btn-primary btn-block m " id="load_data_button" onclick="loadData()"><i class="fa fa-arrow-down"></i> 显示更多</button>';
					}else{
						result+='<button class="btn btn-primary btn-block m"> 没有更多消息</button>';
					}
					
					$('#recommandTopic').append(result);
					$('.img-responsive').zoomify();
				}
			},
			error:function(data){
			}
	    });
}


function loadData(){
	$('#load_data_button').remove();
	getHomePageTopic($('#recommandTopic').children().length,10);
}

function setCarsouelData(){
	 $.ajax({
			type : 'POST',
			dataType:'json', 
			url : ctp + '/interface/homepagetopicSearch',
			data: {
				type:2,//0 推荐预览查询 1关注预览差查询	2热门预览查询 3最新预览查询
				pos_idx:0,
				count:5
			},
			success:function(data){
				if(data.code==200){
					var cover_pic0='';
					//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
					if(data.data[0].cover_pic ==''){
						if(data.data[0].pic_list==''){
							cover_pic0="images/nopic.jpg";
						}else{
							cover_pic0=data.data[0].pic_list[0];
						}
						
					}else{
						cover_pic0=data.data[0].cover_pic;
					}
					
					var cover_pic1='';
					//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
					if(data.data[1].cover_pic ==''){
						if(data.data[1].pic_list==''){
							cover_pic1="images/nopic.jpg";
						}else{
							cover_pic1=data.data[1].pic_list[0];
						}
						
					}else{
						cover_pic1=data.data[1].cover_pic;
					}
					
					var cover_pic2='';
					//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
					if(data.data[2].cover_pic ==''){
						if(data.data[2].pic_list==''){
							cover_pic2="images/nopic.jpg";
						}else{
							cover_pic2=data.data[2].pic_list[0];
						}
						
					}else{
						cover_pic2=data.data[2].cover_pic;
					}
					
					var cover_pic3='';
					//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
					if(data.data[3].cover_pic ==''){
						if(data.data[3].pic_list==''){
							cover_pic3="images/nopic.jpg";
						}else{
							cover_pic3=data.data[3].pic_list[0];
						}
						
					}else{
						cover_pic3=data.data[3].cover_pic;
					}
					
					var cover_pic4='';
					//封面图片是否存在，不存在取pic_list第一张，若还不存在则使用默认图片
					if(data.data[4].cover_pic ==''){
						if(data.data[4].pic_list==''){
							cover_pic4="images/nopic.jpg";
						}else{
							cover_pic4=data.data[4].pic_list[0];
						}
						
					}else{
						cover_pic4=data.data[4].cover_pic;
					}
					var result="";
					result+='<div class="ibox float-e-margins" >';
					result+='<div class="ibox-content " >';
					result+=' <div class="carousel slide" id="carousel2">';
					result+='  <ol class="carousel-indicators">';
					result+='<li data-slide-to="0" data-target="#carousel2" class="active"></li>';
					result+='<li data-slide-to="1" data-target="#carousel2"></li>';
					result+=' <li data-slide-to="2" data-target="#carousel2" ></li>';
					result+=' <li data-slide-to="3" data-target="#carousel2" ></li>';
					result+=' <li data-slide-to="4" data-target="#carousel2" ></li>';
					result+='</ol>';
					result+='   <div class="carousel-inner" >';
					result+='<div class="item active">';
					result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[0].topic_id+','+data.data[0].class_id+','+data.data[0].type+')" class="btn-link">';
					result+='  <img alt="image" style="width:100%;height:400px" src="'+cover_pic0+'">';
				    result+='  <div class="carousel-caption">';
				    result+='  <p>'+data.data[0].title+'</p>';
				    result+='   </div>';
				    result+='	</a>';
				    result+='  </div>';
				    result+='  <div class="item ">';
				    result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[1].topic_id+','+data.data[1].class_id+','+data.data[1].type+')" class="btn-link">';
				    result+='   <img alt="image" style="width:100%;height:400px"   src="'+cover_pic1+'">';
				    result+='  <div class="carousel-caption">';
				    result+='  <p>'+data.data[1].title+'</p>';
				    result+='   </div>';
				    result+='	</a>';
				    result+=' </div>';
				    result+='  <div class="item ">';
				    result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[2].topic_id+','+data.data[2].class_id+','+data.data[2].type+')" class="btn-link">';
				    result+='   <img alt="image" style="width:100%;height:400px"   src="'+cover_pic2+'">';
				    result+='  <div class="carousel-caption">';
				    result+='  <p>'+data.data[2].title+'</p>';
				    result+='   </div>';
				    result+='	</a>';
				    result+=' </div>';
				    result+='  <div class="item ">';
				    result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[3].topic_id+','+data.data[3].class_id+','+data.data[3].type+')" class="btn-link">';
				    result+='   <img alt="image" style="width:100%;height:400px"   src="'+cover_pic3+'">';
				    result+='  <div class="carousel-caption">';
				    result+='  <p>'+data.data[3].title+'</p>';
				    result+='   </div>';
				    result+='	</a>';
				    result+=' </div>';
					result+=' <div class="item">';
					result+='<a javascript:void(0) onclick="Common.openDetailPage('+data.data[4].topic_id+','+data.data[4].class_id+','+data.data[4].type+')" class="btn-link">';
					result+=' <img alt="image" style="width:100%;height:400px" src="'+cover_pic4+'">';
					result+='<div class="carousel-caption">';
					result+='  <p>'+data.data[4].title+'</p>';
					result+='  </div>';
					result+='	</a>';
					result+='   </div>';
					result+=' </div>';
				    result+='<a data-slide="prev" href="carousel.html#carousel2" class="left carousel-control">';
				    result+='   <span class="icon-prev"></span>';
				    result+='  </a>';
				    result+='  <a data-slide="next" href="carousel.html#carousel2" class="right carousel-control">';
				    result+='   <span class="icon-next"></span>';
				    result+='    </a>';
				    result+='  </div>';
					result+='</div>';
					result+='</div>';
					
					$('#carsouel').html(result);
					$('#carousel2').carousel();
				}
			},
			error:function(data){
			}
	    });
	
	
	
}


